from fastapi import APIRouter, Header, Depends

from pydantic.main import BaseModel

from api import ok, mysql
from const import tbl__market_industryOverview, tbl__rank_author

router = APIRouter()


@router.get('/total', summary='首页')
def index():
    userList = [user.__data__ for user in BaseModel.select()]
    return ok(data={'result': userList})

@router.get('/fans', summary='首页')
def index():
    b = BaseModel.select().order_by(BaseModel.up_follower.desc())
    userList = [user.__data__ for user in BaseModel.select()]
    return ok(data={'result': userList})

# @router.get('/search/{id}',summary='搜索')
# def search(id:int):
#     print('参数id',id)
#     return ok(data={222})

#访问数据库
from peewee import *
class BaseModel(Model):
    up_name = CharField(column_name='name', null=True)
    up_img = CharField(column_name='face', null=True)
    up_follower = CharField(column_name='follower', null=True)
    up_following = CharField(column_name='following', null=True)
    up_view = CharField(column_name='view', null=True)
    up_likes = CharField(column_name='likes', null=True)

    class Meta:
        database = mysql
        db_table = 'rank_author_video'


# # 删除表
# Video.drop_table()
# # 创建表
# Video.create_table()

